include("weapons/gmod_tool/DWstargate_base_tool.lua");

--################# Header
TOOL.Category = '(DW-Climate Regulation)'
TOOL.Name = '#Habitafiyer'
TOOL.Command = nil
TOOL.ConfigName = ''
TOOL.Tab = "Life Support"


TOOL.ClientConVar["autolink"] = 1;
TOOL.ClientConVar["autoweld"] = 1;
-- The default model for the GhostPreview
TOOL.ClientConVar["model"] = "models/props_c17/gravestone_cross001a.mdl";
-- Holds modles for a selection in the tooltab and allows individual Angle and Position offsets {Angle=Angle(1,2,3),Position=Vector(1,2,3} for the GhostPreview
TOOL.Models = {
	["models/props_c17/gravestone_cross001a.mdl"] = {},

};

-- Information about the SENT to spawn
TOOL.Entity.Class = "domclimatecont";
TOOL.Entity.Limit = 1;

-- Add the topic texts, you see in the upper left corner
TOOL.Topic["name"] = "Habitafiyer";
TOOL.Topic["desc"] = "A Habitafiyer will make your colonised planet habitable.";
TOOL.Topic[0] = "Left-Click: Spawns a Habitafiyer.";
-- Adds additional "language" - To the end of these files, the string "_*classname*" will be added, using TOOL.Entity["class"]. 
-- E.g. TOOL.Language["Undone"] will add the language "Undone_prop_physics" when TOOL.Entity["class"] is "prop_physics"
TOOL.Language["Undone"] = "Habitafiyer Removed";
TOOL.Language["Cleanup"] = "Habitafiyer";
TOOL.Language["Cleaned"] = "Your Habitafiyer's have been razed";
TOOL.Language["SBoxLimit"] = "You have reach your Habitafiyer limit!";
--################# Code

--################# LeftClick Toolaction @aVoN
function TOOL:LeftClick(t)
		if(t.Entity and t.Entity:IsPlayer()) then return false end;
	if(CLIENT) then return true end;
	
	if(t.Entity and t.Entity:GetClass() == self.Entity.Class) then
		t.Entity.Color = Color(r,g,b,255);
		-- THIS FUNCTIONS SAVES THE MODIFIED KEYS TO THE SENT, SO THEY ARE AVAILABLE WHEN COPIED WITH DUPLICATOR!
		t.Entity:UpdateKeys(_,_,_,r,g,b,shaft,explosion,explosion_colorize,add_cannon_velocity);
		return true;
	end

	if(not self:CheckLimit()) then return false end;
	local p = self:GetOwner();
	local model = self:GetClientInfo("model");
	--######## Spawn SENT
	local e = self:SpawnSENT(p,t,shoot,explode,model,r,g,b,shaft,explosion,explosion_colorize,add_cannon_velocity);
		self:AutoLink(e,t.Entity); -- Link to that energy system, if valid
		--######## Weld things?
	Register_Owner(e, p)
	local c = self:Weld(e,t.Entity,util.tobool(self:GetClientNumber("autoweld")));
	--######## Cleanup and undo register
	self:AddUndo(p,e,c);
	self:AddCleanup(p,c,e);
	return true;
end

--################# The PreEntitySpawn function is called before a SENT got spawned. Either by the duplicator or with the stool.@aVoN
function TOOL:PreEntitySpawn(p,e,shoot,explode,model,r,g,b,shaft,explosion,explosion_colorize,add_cannon_velocity)
	local model = model or self.ClientConVar["model"];
	e:SetModel(model);
end

--################# Controlpanel @aVoN
function TOOL:ControlsPanel(Panel)
			Panel:CheckBox("Autoweld","defence_cannon_autoweld");
	end

TOOL:Register();